<!DOCTYPE html>
<html lang="zh_CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>多继承（this与super的运用）</title>
  </head>
  <style></style>
  <body></body>
  <script>
    function extend(sub, sup) {
      sub.prototype = Object.create(sup.prototype)
      Object.defineProperty(sub.prototype, 'constructor', {
        value: sub,
        enumerable: false,
      })
    }

    const Request = {
      ajax() {
        return '后台请求'
      },
    }
    const UserService = {
      __proto__: Request,
      userList() {
        // this 是调用上下文的指向
        console.log('this', this)
        // super 是当前对象__proto__的指向
        console.log(super.ajax() + '用户列表')
      },
    }

    function User() {}
    User.prototype.info = function () {
      console.log('用户信息')
    }
    function Admin() {}
    extend(Admin, User)
    Admin.prototype.show = function () {
      console.log('管理员')
    }
    Admin.prototype = Object.assign(Admin.prototype, UserService)
    let admin = new Admin()
    admin.show()
    admin.info()
    admin.userList()
  </script>
</html>
